<template>
	<view>
		<!-- 橙色部分 -->
		<view class="situation">
			<!-- 日期 -->
			<picker mode="date" :value="date" start="2018-09-01" end="2021-09-01" @change="bindDateChange" fields="month">
				<view>{{date}}</view>
			</picker>
			<view class="divider"></view>
			<view class="situation_title">
				<view @click="showIncome">收入</view>
				<view class="longitudinal"></view>
				<view @click="showSpending">支出</view>
			</view>
		</view>
		<!-- 数据部分 -->
		<view class="income_contain">
			<view v-for="(item, index) in content.detail" :key="index">
				<view class="income_item">
					<view>{{item.name}}</view>
					<view>{{item.value}}</view>
				</view>
				<!-- 内容明细 -->
				<view class="income_detail" v-for="(item, index) in item.detail" :key="index" v-if="item.detail == null">
					<view>{{item.name}}</view>
					<view>{{item.value}}</view>
				</view>
				<!-- <view class="income_editor" @click="changePop">修改</view> -->
				<view class="divider"></view>
			</view>
			<!-- 今日收入 -->
			<view class="income_today">
				<view>{{content.total.title}}</view>
				<view>{{content.total.value}}</view>
			</view>
		</view>
		<!-- 显示弹窗 -->
		<view v-if="showPop">
			<view class="popup" @click="hidePop()"></view>
			<view style="display: flex; justify-content: center;">
				<view class="popup_contain">
					<view>修改金额</view>
					<view class="contain_price">
						<text>￥</text>
						<input focus="true" type="digit" @focus="changeHeight" adjust-position="false" />
						<button>确定</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showPop: false,
				keyboardHeight: 0,
				date: '2021-3',
				content: ''
			}
		},
		methods: {
			// 初始化参数
			initData: function() {
				// 获取支出数据
				var income_content = {
					total: {
						title: '今日收入',
						value: '￥18500',
					},
					detail: [{
							name: '乐器收入',
							value: '￥10000.00',
							detail: [{
								name: '备注：吉他',
								value: '￥5000',
							}]
						},
						{
							name: '活动收入',
							value: '￥5500.00'
						},
						{
							name: '其他收入',
							value: '￥3000.00'
						}
					]
				}
				this.content = income_content;
			},
			showIncome: function() {
				// 获取收入信息并设置
				this.initData();
			},
			showSpending: function() {
				// 展示支出信息
				var spending_content = {
					total: {
						title: '今日支出',
						value: '￥10500.00',
					},
					detail: [{
							name: '运营成本',
							value: '￥5000.00',
							detail: [{
								name: '培训费',
								value: '￥2000.00',
							}, {
								name: '乐器采购',
								value: '￥1000.00',
							}, {
								name: '其他教材成本',
								value: '￥2000.00',
							}]
						},
						{
							name: '管理成本',
							value: '￥0.00',
							detail: [{
								name: '地租',
								value: '￥0.00',
							}, {
								name: '水电费',
								value: '￥0.00',
							}, {
								name: '财务费用',
								value: '￥0.00',
							}, {
								name: '店长工资',
								value: '￥0.00',
							}, {
								name: '兼职人员费用',
								value: '￥0.00',
							}, {
								name: '其他管理费用',
								value: '￥0.00',
							}]
						},
						{
							name: '销售成本',
							value: '￥5500.00',
							detail: [{
									name: '广告费用',
									value: '￥500.00',
								}, {
									name: '招生提成',
									value: '￥1000.00',
								}, {
									name: '活动费用',
									value: '￥4000.00',
								}, {
									name: '其他销售费用',
									value: '￥0.00',
								}

							]
						}
					]
				}
				this.content = spending_content;
			},
			changePop: function(){
				this.showPop = true;
			},
			hidePop: function(){
				this.showPop = false;
			},
			changeHeight: function(event){
				console.log(event.detail.height);
				this.keyboardHeight = event.detail.height*1;
			}
		},
		onLoad: function(e) {
			if(e.type){
				if(e.type == 0) this.initData();
				else this.showSpending();
			}else{
				this.initData();
			}
		},
	}
</script>

<style>
	page {
		background-color: #F3F5F7;
	}

	.situation {
		background-color: #FD973F;
		width: 100%;
		/* height: 300rpx; */
		border-radius: 0 0 30% 30%;
		display: flex;
		flex-direction: column;
		text-align: center;
	}

	.situation picker {
		/* margin-top: 20rpx; */
		color: #fff;
	}

	.divider {
		height: 2rpx;
		/* width: 100%; */
		background-color: #eee;
		margin: 20rpx;
	}

	.longitudinal {
		height: 100rpx;
		margin: -20rpx 0;
		width: 2rpx !important;
		background-color: #eee;
	}

	.situation_title {
		display: flex;
		color: #fff;
		margin-bottom: 100rpx;
	}

	.situation_title view {
		width: 50%;
	}

	/* 收入明细 */
	.income_contain {
		margin: -80rpx 30rpx 60rpx 30rpx;
		background-color: #fff;
		/* height: 300rpx; */
		border-radius: 26rpx;
		padding: 10rpx 30rpx;
		/* box-shadow: 0rpx 10rpx 10rpx 1rpx #888888; */
	}

	.income_item {
		display: flex;
		justify-content: space-between;
		/* font-size: 30rpx; */
		line-height: 70rpx;
	}

	.income_detail {
		display: flex;
		justify-content: space-between;
		color: #999;
		font-size: 28rpx;
		margin-top: 10rpx;
		margin-left: 60rpx;
	}

	.income_editor {
		color: #FD973F;
		font-size: 28rpx;
		display: flex;
		justify-content: flex-end;
		margin: 15rpx 0rpx;
	}

	.income_today {
		display: flex;
		justify-content: space-between;
		color: #FD973F;
		font-size: 36rpx;
		margin-bottom: 20rpx;
	}
	
	.popup{
		width: 100%;
		height: 100%;
		position: fixed;
		background-color: rgba(0,0,0, 0.4);
		top: 0;
		display: flex;
		justify-content: center;
	}
	
	.popup_contain{
		position: fixed;
		width: 80%;
		height: 80px;
		bottom: 50%;
		background-color: #fff;
		border-radius: 24rpx;
		z-index: 999;
		padding: 5%;
	}
	
	.contain_price{
		display: flex;
		border-bottom: #ddd solid 1rpx;
		padding-bottom: 10rpx;
		margin: 30rpx 0rpx;
		align-items: center;
	}
	
	.contain_price text{
		font-size: 55rpx;
		font-weight: bold;
		margin-right: 20rpx;
	}
	
	.contain_price button{
		background-color: #FD973F;
		color: #fff;
		height: 70rpx;
		font-size: 30rpx;
		margin-right: 0rpx;
		align-items: center;
	}
</style>
